package com.cjzuji.rental.controller.order;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cjzuji.rental.mapper.RequestMapper;
import com.cjzuji.rental.pojo.RequestHeard;
import com.cjzuji.rental.service.RenRZuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order/renzuzu")
@Api(value = "人人租订单类")
//@Component
//http://127.0.0.1:9099/order/renzuzu/getRrzInfo
public class RenRZuController {
    @Autowired
    RequestMapper requestMapper;
    @Autowired
    RenRZuService renRZuService;
    private static final Logger logger = LoggerFactory.getLogger(RenRZuController.class);

    @GetMapping("/getRrzInfo")
    @ApiOperation(value = "获取人人租所有订单列表详情", notes = "人人租所有订单列表和订单详情")
    //@Scheduled(fixedRate = 60 * 60 * 24000)
    public List<Map<String, Object>> getRrzInfo() {
        //从数据库获取
        try {
            QueryWrapper<RequestHeard> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("id",1);
            RequestHeard requestHeard = requestMapper.selectOne(queryWrapper);
            String authorization = requestHeard.getRrzauthorization();
            String cookie = requestHeard.getCookie();
            List<Map<String, Object>> result = renRZuService.getRenRZuList(authorization,cookie);
            return result;
        } catch (Exception e) {
            logger.error("获取 人人租所有 订单列表详情失败");
            return null;
        }
    }

    //获取租用中的数据
    @PutMapping("/upDateBill")
    @ApiOperation(value = "获取租用中的数据", notes = "租用中的数据")
    //@Scheduled(fixedRate = 60 * 60 * 24000)
    public List<Map<String, Object>> upDateBill(){
        //从数据库获取
        try {
            QueryWrapper<RequestHeard> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("id",1);
            RequestHeard requestHeard = requestMapper.selectOne(queryWrapper);
            String authorization = requestHeard.getRrzauthorization();
            String cookie = requestHeard.getCookie();
            List<Map<String, Object>> result = renRZuService.upDateBillList(authorization, cookie);
            return result;
        }catch (Exception e){
            logger.error("获取 人人租租用中 的数据失败");
            return null;
        }
    }

    //获取逾期的订单数据
    @PutMapping("/getOverdue")
    @ApiOperation(value = "获取逾期的订单数据", notes = "获取逾期的订单数据")
    //@Scheduled(fixedRate = 60 * 60 * 24000)
    public List<Map<String, Object>> getOverdue(){
        try {
            QueryWrapper<RequestHeard> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("id",1);
            RequestHeard requestHeard = requestMapper.selectOne(queryWrapper);
            String cookie = requestHeard.getRenrzyqcookie();
            List<Map<String, Object>> result = renRZuService.getOverdue(cookie);
            return result;
        } catch (Exception e) {
            logger.error("获取 人人租逾期 订单列表详情失败");
            return null;
        }
    }
}
